package com.jiot.controller.device;

import com.zg.cloud.BaseResponse;
import com.zg.cloud.CommonEnum;
import com.zg.cloud.annotation.TokenCheck;
import com.zg.cloud.service.AlarmService;
import com.zg.cloud.utils.BaseUtil;
import com.zg.cloud.utils.DateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import req.alarm.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author liling
 * @date 2020/10/20 10:11
 * @description
 **/
@RestController
@RequestMapping("/device/alarm")
@Api(value = "告警模块")
public class AlarmController {

    @Resource
    private AlarmService alarmService;

    @PostMapping("/app/list")
    @TokenCheck
    @ApiOperation(value = "查询报警信息", notes = "device")
    public BaseResponse appList(@RequestBody @Valid AppGetAlarmListReq appGetAlarmListReq) {
        return new BaseResponse(alarmService.appList(appGetAlarmListReq));
    }

    @PostMapping("/server/info")
    @TokenCheck
    @ApiOperation(value = "请求服务页面数据", notes = "device")
    public BaseResponse serverInfo(@RequestBody @Valid AppGetAlarmServerInfoReq appGetAlarmServerInfoReq) {
        return new BaseResponse(alarmService.serverInfo(appGetAlarmServerInfoReq));
    }

    @PostMapping("/server/info/all")
    @TokenCheck
    @ApiOperation(value = "请求所有服务页面数据", notes = "device")
    public BaseResponse serverInfoAll() {
        return new BaseResponse(alarmService.serverInfoAll());
    }

    @PostMapping("/ignore/alarm")
    @TokenCheck
    @ApiOperation(value = "忽略报警", notes = "device")
    public BaseResponse ignoreAlarm(@RequestBody @Valid AppIgnoreAlarmReq appIgnoreAlarmReq) {
        alarmService.ignoreAlarm(appIgnoreAlarmReq);
        return new BaseResponse();
    }

    @PostMapping("/status/list")
    @TokenCheck
    @ApiOperation(value = "报警信息状态值", notes = "device", hidden = true)
    public BaseResponse statusList() {
        return new BaseResponse(alarmService.statusList());
    }

    @PostMapping("/update/status/by/project")
    @TokenCheck
    @ApiOperation(value = "根据项目批量修改状态值", notes = "device", hidden = true)
    public BaseResponse updateStatusByProject(@RequestBody @Valid BatchUpdateStatusReq batchUpdateStatusReq) {
        return new BaseResponse(alarmService.batchUpdateStatus(batchUpdateStatusReq));
    }

    @PostMapping("/device/list")
    @TokenCheck
    @ApiOperation(value = "报警设备列表", notes = "device")
    public BaseResponse deviceList(@RequestBody @Valid GetAlarmDeviceInfoByProjectIdsReq getAlarmDeviceInfoByProjectIdsReq) {
        return new BaseResponse(alarmService.deviceList(getAlarmDeviceInfoByProjectIdsReq));
    }

    @PostMapping("/type/list")
    @TokenCheck
    @ApiOperation(value = "报警类型列表", notes = "device")
    public BaseResponse typeList() {
        return new BaseResponse(alarmService.alarmTypeList());
    }

    @PostMapping("/device/snapshot")
    @TokenCheck
    @ApiOperation(value = "报警设备快照", notes = "device")
    public BaseResponse deviceSnapshot(@RequestBody @Valid GetDeviceAlarmSnapshotReq getDeviceAlarmSnapshotReq) {
        return new BaseResponse(alarmService.deviceSnapshot(getDeviceAlarmSnapshotReq));
    }

    @PostMapping("/newest/count")
    @TokenCheck
    @ApiOperation(value = "最新报警信息数量", notes = "device")
    public BaseResponse newestCount() {
        return new BaseResponse(alarmService.newestCount());
    }
}
